﻿
using IHISCETeim.BLL;
using IHISCETeim.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using IHISCETeim.Library;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;


namespace IHISCETeim.Web.MachineSys.SAPModel
{
    public partial class SAPDfctPrdFctryEdit : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "SAPDfctPrdList"; }
        }

        protected int DfctID
        {
            get
            {

                return GetRequestValue<int>("DfctID", 0);
            }
        }
        /// <summary>
        /// 操作方式
        /// </summary>
        protected string action
        {
            get
            {

                return GetRequestValue<string>("action", "View");
            }
        }

        protected short TypeID
        {
            get
            {

                return GetRequestValue<short>("typeid", 0);
            }
        }

        protected string tag
        {
            get
            {
                return TypeID == 0 ? "出厂" : "还厂";
            }
        }

        private SAPDfctPrdInfo _obj = null;

        public SAPDfctPrdInfo obj
        {
            get
            {
                if (_obj == null)
                {
                    if (DfctID == 0)
                    {
                        _obj = new SAPDfctPrdInfo();
                    }
                    else {
                        _obj = SAPDfctPrdController.GetList(DfctID);
                    }
                }

                return _obj;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                add();
            }
            //JsonConvert.SerializeObject(obj)
            LoadInfo();
        }

        private void LoadInfo()
        {

            List<SAPDfctPrdFctryInfo> listParts = SAPDfctPrdController.GetFctryAll(DfctID, TypeID);


            this.rpParts.DataSource = listParts;
            this.rpParts.DataBind();

        }
        private void add()
        {

            SAPDfctPrdFctryInfo objdetail = Request.SerializableObject<SAPDfctPrdFctryInfo>();
            objdetail.Type = TypeID;

            if (SAPDfctPrdController.AddFctry(objdetail) > 0)
            {
                SuccessJson(String.Format("已成功添加{0}记录.",tag), this.DWZRef);
            }
            else {
                ErrorJson(String.Format("添加{0}记录失败！", tag));
            }


           
        }
    }
}